********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW											
*This File: Table 2/3
*Version: 	vFinal						
*Date: 		2020-11-01			
********************************************************************************



********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
*Q1
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************


********************************************************************************
********************************************************************************
*Add Data Trade
********************************************************************************
********************************************************************************

*GENERATE FIRST HALF YEAR GROWTH JAN-JUNE, Q1
use "${root}\workfiles\trade_2002_2020_M_analysis_wide.dta", replace

*!!!SELECT TIME PERIOD (MONTHS)
keep if SAMPLE==21
keep if monat<=3

keep jahr monat datum land_id land_str land_iso2								///
export_chf_mia import_chf_mia

gen trade_chf_mia=export_chf_mia+import_chf_mia

collapse (sum) export_chf_mia import_chf_mia trade_chf_mia, by(jahr land_id land_str land_iso2)
keep if jahr>=2019

tsset land_id jahr

foreach var of varlist export_chf_mia import_chf_mia trade_chf_mia {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

keep if jahr==2020
keep land_id land_str land_iso2 export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct
sort land_str

save "${root}\temp\reg_cs_trade_Q1.dta", replace


*ADD 2019 TOTAL TRADE FOR SAMPLE RESTRICTIONS
use "${root}\workfiles\trade_2002_2020_M_analysis_wide.dta", replace

keep if SAMPLE==21
keep if jahr==2019
keep jahr monat datum land_id land_str land_iso2								///
export_chf_mia import_chf_mia

gen trade_chf_mia=export_chf_mia+import_chf_mia

foreach x in 10 25 40 50 {
    local y=`x'/1000
	gen trade_Q1_Q2_`x'mio=.
	replace trade_Q1_Q2_`x'mio=1 if trade_chf_mia>=`y' & monat>=1 & monat<=6
}

collapse (sum) export_chf_mia import_chf_mia trade_chf_mia trade_Q1_Q2*, by(jahr land_id land_str land_iso2)

keep  land_iso2 export_chf_mia import_chf_mia trade_chf_mia trade_Q1_Q2*

merge 1:m land_iso2 using "${root}\temp\reg_cs_trade_Q1.dta"
keep if _merge==3
drop _merge

keep land_str land_iso2 export_chf_mia import_chf_mia trade_chf_mia 			///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct trade_Q1_Q2*

order  land_str land_iso2 export_chf_mia import_chf_mia trade_chf_mia 			///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct trade_Q1_Q2*

rename *_chf_mia *_chf_mia_2019

save "${root}\temp\reg_cs_trade_Q1.dta", replace



********************************************************************************
********************************************************************************
*Add PMI 
********************************************************************************
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\pmi_dta_raw.csv", clear 

rename *manpm country_*
rename usmanmepm country_us

split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

foreach var of varlist country_at-country_vn {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

rename country_*_std country_std_*

keep if year>2018
order date year month day
reshape long country_ country_std_, i(date) j(country) string

rename country_ pmi
rename country_std_ pmi_std
replace country=strupper(country)

order country date year month day pmi pmi_std
sort country date year month day pmi pmi_std

*!!!SELECT TIME PERIOD (MONTHS)
keep if month<=3
collapse (mean) pmi pmi_std, by(country year)
egen land_id=group(country)
tsset land_id year

foreach var of varlist pmi {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

foreach var of varlist pmi_std {
	gen `var'_delta=(`var'-l.`var')
}

*SELECT TIME PERIOD (YEAR)
keep if year==2020

order country year pmi pmi_std pmi_dpct pmi_std_delta
drop land_id
rename country land_iso2

merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_Q1.dta"
drop if _merge==1
drop _merge

drop year 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
pmi pmi_std pmi_dpct pmi_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_Q1.dta", replace

********************************************************************************
********************************************************************************
*Add Konsumentenstimmung
********************************************************************************
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\cons_dta_raw.csv", clear 

foreach var of varlist alsurv0002- cnsurv0052 cosurv1000- zasurv0018 {
	local var2 = substr("`var'", 1,2)
	rename `var' country_`var2'
}

foreach var of varlist cons2_cy_tot_cof_bs_m-cons2_ro_tot_cof_bs_m {
	local var2 = substr("`var'", 7,2)
	rename `var' country_`var2'
}

split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

foreach var of varlist country* {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

keep if year>2018
order date year month day
rename country_*_std country_std_*

reshape long country_ country_std_, i(date) j(country) string

rename country_ kst
rename country_std_ kst_std
replace country=strupper(country)

order country date year month day kst kst_std
sort country date year month day kst kst_std

*!!!SELECT TIME PERIOD (MONTH)
keep if month<=3

collapse (mean) kst kst_std, by(country year)
egen land_id=group(country)
tsset land_id year

foreach var of varlist kst {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

foreach var of varlist kst_std {
	gen `var'_delta=(`var'-l.`var')
}

*SELECT TIME PERIOD (YEAR)
keep if year==2020

order country year kst kst_std kst_dpct kst_std_delta
drop land_id
rename country land_iso2

merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_Q1.dta"
drop if _merge==1
drop _merge
drop year 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_Q1.dta", replace


********************************************************************************
********************************************************************************
*Add COVID-19 CASES 
*******************************************************************************
********************************************************************************

import delimited "${root}\data\COVID_DATA\covid-daily-vs-total-cases-per-million_v20200828.csv", ///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 

rename entity land_str
rename code land_iso3
rename dailyconfirmedcasespermillion year
rename totalconfirmedcasespermillioncas  daily_per_mio
rename v6 total_per_mio

*ADAPT MAIN VARIABLES 
replace daily_per_mio = 0 if daily_per_mio == .
replace total_per_mio = 0 if total_per_mio == .
gen total_per_1000=total_per_mio/1000

*Date Variable
split date, parse(" ")
rename date1 month
rename date2 day

drop if month=="Dec"

replace month="1" if month=="Jan"
replace month="2" if month=="Feb"
replace month="3" if month=="Mar"
replace month="4" if month=="Apr"
replace month="5" if month=="May"
replace month="6" if month=="Jun"
replace month="7" if month=="Jul"
replace month="8" if month=="Aug"

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen monday = date - cond(dow(date) == 0, 6, dow(date) - 1)
format monday %tddd.nn.YY

*MERGE COUNTRY IDENTIFIES
merge m:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta"
keep if _merge==3
drop _merge 

*!!!SELECT DATE
sort land_str year month day
keep if date==td(31mar2020)

drop land_num year month day date monday land_iso3 daily_per_mio
order land_str land_iso2  total_per_mio total_per_1000

*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_Q1.dta"
drop _merge 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct						///
total_per_mio total_per_1000 													///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q1.dta", replace

********************************************************************************
********************************************************************************
*Add Government Response
*******************************************************************************
********************************************************************************

import delimited "${root}\data\COVID_DATA\OxCGRT_v20200828.txt", 	///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 

rename countryname land_str
rename countrycode land_iso3
rename stringencyindex stringency_index
rename governmentresponseindex gov_index

keep land_str land_iso3 stringency_index gov_index date

*Date Variable
tostring date, replace
gen year=substr(date, 1,4)
gen month=substr(date, 5,2)
gen day=substr(date, 7,2)

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen date_mo = date - cond(dow(date) == 0, 6, dow(date) - 1)
format date_mo %tddd.nn.YY

sort land_str date_mo

*!!!SELECT DATE
keep if date<=td(31mar2020)
collapse (mean) stringency_index gov_index, by(land_str land_iso3)

*MERGE COUNTRY IDENTIFIES
merge m:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta"
keep if _merge==3
drop _merge 

keep land_iso2 stringency_index gov_index

*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q1.dta"
drop _merge 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct						///
total_per_mio total_per_1000 stringency_index gov_index							///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q1.dta", replace

********************************************************************************
********************************************************************************
*Add Population Data
********************************************************************************
********************************************************************************

import excel "${root}\data\Country_Data_Other\Population_Worldbank.xls",		///
 sheet("Data") cellrange(A5:BL268) clear

rename A land_str
rename B land_iso3
rename BL population_2019

keep land* population

gen population_2019_mio=population_2019/(1000*1000)
drop population_2019

merge 1:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta", keepusing(land_iso2)
keep if _merge==3
drop _merge 


*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q1.dta"
drop if _merge==1
drop _merge

gen quarter=1

order land_str land_iso2 land_iso3  quarter										///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
total_per_mio total_per_1000 stringency_index gov_index							///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta			///
export_chf_mia_2019 import_chf_mia_2019 trade_chf_mia_2019 population_2019_mio trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_pop_Q1.dta", replace


********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
*Q2
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

********************************************************************************
********************************************************************************
*Add Data Trade
********************************************************************************
********************************************************************************

*GENERATE FIRST HALF YEAR GROWTH JAN-JUNE, Q2
use "${root}\workfiles\trade_2002_2020_M_analysis_wide.dta", replace

*!!!SELECT TIME PERIOD (MONTHS)
keep if SAMPLE==21
keep if monat>3 & monat<=6

keep jahr monat datum land_id land_str land_iso2								///
export_chf_mia import_chf_mia

gen trade_chf_mia=export_chf_mia+import_chf_mia

collapse (sum) export_chf_mia import_chf_mia trade_chf_mia, by(jahr land_id land_str land_iso2)
keep if jahr>=2019

tsset land_id jahr

foreach var of varlist export_chf_mia import_chf_mia trade_chf_mia {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

keep if jahr==2020
keep land_id land_str land_iso2 export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct
sort land_str

save "${root}\temp\reg_cs_trade_Q2.dta", replace


*ADD 2019 TOTAL TRADE FOR SAMPLE RESTRICTIONS
use "${root}\workfiles\trade_2002_2020_M_analysis_wide.dta", replace

keep if SAMPLE==21
keep if jahr==2019
keep jahr monat datum land_id land_str land_iso2								///
export_chf_mia import_chf_mia

gen trade_chf_mia=export_chf_mia+import_chf_mia

foreach x in 10 25 40 50 {
    local y=`x'/1000
	gen trade_Q1_Q2_`x'mio=.
	replace trade_Q1_Q2_`x'mio=1 if trade_chf_mia>=`y' & monat>=1 & monat<=6
}


collapse (sum) export_chf_mia import_chf_mia trade_chf_mia trade_Q1_Q2*, by(jahr land_id land_str land_iso2)

keep  land_iso2 export_chf_mia import_chf_mia trade_chf_mia trade_Q1_Q2* 

merge 1:m land_iso2 using "${root}\temp\reg_cs_trade_Q2.dta"
keep if _merge==3
drop _merge

keep land_str land_iso2 export_chf_mia import_chf_mia trade_chf_mia 			///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct trade_Q1_Q2*

order  land_str land_iso2 export_chf_mia import_chf_mia trade_chf_mia 			///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct trade_Q1_Q2*

rename *_chf_mia *_chf_mia_2019

save "${root}\temp\reg_cs_trade_Q2.dta", replace


********************************************************************************
********************************************************************************
*Add PMI 
********************************************************************************
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\pmi_dta_raw.csv", clear 

rename *manpm country_*
rename usmanmepm country_us

split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

foreach var of varlist country_at-country_vn {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

rename country_*_std country_std_*

keep if year>2018
order date year month day
reshape long country_ country_std_, i(date) j(country) string

rename country_ pmi
rename country_std_ pmi_std
replace country=strupper(country)

order country date year month day pmi pmi_std
sort country date year month day pmi pmi_std

*!!!SELECT TIME PERIOD (MONTHS)
keep if month>3 & month<=6
collapse (mean) pmi pmi_std, by(country year)
egen land_id=group(country)
tsset land_id year

foreach var of varlist pmi {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

foreach var of varlist pmi_std {
	gen `var'_delta=(`var'-l.`var')
}

*SELECT TIME PERIOD (YEAR)
keep if year==2020

order country year pmi pmi_std pmi_dpct pmi_std_delta
drop land_id
rename country land_iso2

merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_Q2.dta"
drop if _merge==1
drop _merge

drop year 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
pmi pmi_std pmi_dpct pmi_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_Q2.dta", replace

********************************************************************************
********************************************************************************
*Add Konsumentenstimmung
********************************************************************************
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\cons_dta_raw.csv", clear 

foreach var of varlist alsurv0002- cnsurv0052 cosurv1000- zasurv0018 {
	local var2 = substr("`var'", 1,2)
	rename `var' country_`var2'
}

foreach var of varlist cons2_cy_tot_cof_bs_m-cons2_ro_tot_cof_bs_m {
	local var2 = substr("`var'", 7,2)
	rename `var' country_`var2'
}

split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

foreach var of varlist country* {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

keep if year>2018
order date year month day
rename country_*_std country_std_*

reshape long country_ country_std_, i(date) j(country) string

rename country_ kst
rename country_std_ kst_std
replace country=strupper(country)

order country date year month day kst kst_std
sort country date year month day kst kst_std

*!!!SELECT TIME PERIOD (MONTH)
keep if month>3 & month<=6

collapse (mean) kst kst_std, by(country year)
egen land_id=group(country)
tsset land_id year

foreach var of varlist kst {
	gen `var'_dpct=(`var'-l.`var')/(l.`var')*100
}

foreach var of varlist kst_std {
	gen `var'_delta=(`var'-l.`var')
}

*SELECT TIME PERIOD (YEAR)
keep if year==2020

order country year kst kst_std kst_dpct kst_std_delta
drop land_id
rename country land_iso2

merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_Q2.dta"
drop if _merge==1
drop _merge
drop year 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_Q2.dta", replace


********************************************************************************
********************************************************************************
*Add COVID-19 CASES 
*******************************************************************************
********************************************************************************

import delimited "${root}\data\COVID_DATA\covid-daily-vs-total-cases-per-million_v20200828.csv", ///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 

rename entity land_str
rename code land_iso3
rename dailyconfirmedcasespermillion year
rename totalconfirmedcasespermillioncas  daily_per_mio
rename v6 total_per_mio

*ADAPT MAIN VARIABLES 
replace daily_per_mio = 0 if daily_per_mio == .
replace total_per_mio = 0 if total_per_mio == .
gen total_per_1000=total_per_mio/1000

*Date Variable
split date, parse(" ")
rename date1 month
rename date2 day

drop if month=="Dec"

replace month="1" if month=="Jan"
replace month="2" if month=="Feb"
replace month="3" if month=="Mar"
replace month="4" if month=="Apr"
replace month="5" if month=="May"
replace month="6" if month=="Jun"
replace month="7" if month=="Jul"
replace month="8" if month=="Aug"

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen monday = date - cond(dow(date) == 0, 6, dow(date) - 1)
format monday %tddd.nn.YY

*MERGE COUNTRY IDENTIFIES
merge m:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta"
keep if _merge==3
drop _merge 

*!!!SELECT DATE
sort land_str year month day
keep if date==td(30jun2020)

drop land_num year month day date monday land_iso3 daily_per_mio
order land_str land_iso2  total_per_mio total_per_1000

*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_Q2.dta"
drop _merge 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct						///
total_per_mio total_per_1000 													///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q2.dta", replace

********************************************************************************
********************************************************************************
*Add Government Response
*******************************************************************************
********************************************************************************

import delimited "${root}\data\COVID_DATA\OxCGRT_v20200828.txt", 	///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 

rename countryname land_str
rename countrycode land_iso3
rename stringencyindex stringency_index
rename governmentresponseindex gov_index

keep land_str land_iso3 stringency_index gov_index date

*Date Variable
tostring date, replace
gen year=substr(date, 1,4)
gen month=substr(date, 5,2)
gen day=substr(date, 7,2)

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen date_mo = date - cond(dow(date) == 0, 6, dow(date) - 1)
format date_mo %tddd.nn.YY

sort land_str date_mo

*!!!SELECT DATE
keep if date>td(31mar2020) & date<=td(30jun2020)
collapse (mean) stringency_index gov_index, by(land_str land_iso3)

*MERGE COUNTRY IDENTIFIES
merge m:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta"
keep if _merge==3
drop _merge 

keep land_iso2 stringency_index gov_index

*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q2.dta"
drop _merge 

order land_str land_iso2 														///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct						///
total_per_mio total_per_1000 stringency_index gov_index							///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q2.dta", replace

********************************************************************************
********************************************************************************
*Add Population Data
********************************************************************************
********************************************************************************

import excel "${root}\data\Country_Data_Other\Population_Worldbank.xls",		///
 sheet("Data") cellrange(A5:BL268) clear

rename A land_str
rename B land_iso3
rename BL population_2019

keep land* population

gen population_2019_mio=population_2019/(1000*1000)
drop population_2019

merge 1:1 land_iso3 using "${root}\temp\UNCTAD_iso2_iso3.dta", keepusing(land_iso2)
keep if _merge==3
drop _merge 


*MERGE MAIN DATA SET
merge 1:1 land_iso2 using "${root}\temp\reg_cs_trade_pmi_kst_covid19_Q2.dta"
drop if _merge==1
drop _merge

gen quarter=2

order land_str land_iso2 land_iso3  quarter										///
export_chf_mia_dpct import_chf_mia_dpct trade_chf_mia_dpct 						///
total_per_mio total_per_1000 stringency_index gov_index							///
pmi pmi_std pmi_dpct pmi_std_delta kst kst_std kst_dpct kst_std_delta			///
export_chf_mia_2019 import_chf_mia_2019 trade_chf_mia_2019 population_2019_mio trade_Q1_Q2*

save "${root}\temp\reg_cs_trade_pmi_kst_covid19_pop_Q2.dta", replace


********************************************************************************
********************************************************************************
*APPEND Q1 & Q2 DATA
********************************************************************************
********************************************************************************

use "${root}\temp\reg_cs_trade_pmi_kst_covid19_pop_Q1.dta", clear
append using "${root}\temp\reg_cs_trade_pmi_kst_covid19_pop_Q2.dta"

sort land_iso2  quarter

egen land_id=group(land_iso2)

tsset land_id quarter

foreach var of varlist total_per_mio total_per_1000 {
 
	replace `var'=`var'-l.`var' if quarter==2
 
}

save "${root}\temp\reg_panel_trade_pmi_kst_covid19_pop_Q1_Q2.dta", replace

********************************************************************************
********************************************************************************
*REGRESSIONS
********************************************************************************
********************************************************************************

use "${root}\temp\reg_panel_trade_pmi_kst_covid19_pop_Q1_Q2.dta", replace

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*SELECT CUTOFF TRADE
global EST_SAMPLE "trade_chf_mia_2019>0.5 & trade_Q1_Q2_25mio==6"
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

capture gen top10=1 if inlist(land_iso2, "DE", "IT", "FR", "AT","GB", "NL", "ES") |		///
inlist(land_iso2, "US","JP", "CN")

*Table 2: EXPORTE

*Column 7
reg export_chf_mia_dpct total_per_1000 i.quarter if $EST_SAMPLE, cluster(land_id)
codebook land_iso2 if e(sample)==1
capture gen esample_covid=1 if e(sample)==1 

*Column 8
reg export_chf_mia_dpct stringency_index i.quarter if esample_covid==1, cluster(land_id)
codebook land_iso2 if e(sample)==1

*Column 9
reg export_chf_mia_dpct total_per_1000 stringency_index  i.quarter if esample_covid==1, cluster(land_id)
codebook land_iso2 if e(sample)==1

*Column 10
reg export_chf_mia_dpct kst_std total_per_1000 stringency_index i.quarter if $EST_SAMPLE, cluster(land_id) 
codebook land_iso2 if e(sample)==1
capture gen esample_kst=1 if e(sample)==1

*Column 6
reg export_chf_mia_dpct kst_std i.quarter if esample_kst==1, cluster(land_id)
codebook land_iso2 if e(sample)==1



*Table 3: IMPORTE
*Column 7
reg import_chf_mia_dpct total_per_1000 i.quarter if  esample_covid==1, cluster(land_id)
codebook land_iso2 if e(sample)==1

*Column 8
reg import_chf_mia_dpct stringency_index i.quarter if esample_covid==1, cluster(land_id)
codebook land_iso2 if e(sample)==1

*Column 9
reg import_chf_mia_dpct total_per_1000 stringency_index  i.quarter if esample_covid==1 , cluster(land_id)
codebook land_iso2 if e(sample)==1

*Column 10
reg import_chf_mia_dpct pmi_std total_per_1000 stringency_index i.quarter if $EST_SAMPLE, cluster(land_id)
capture  gen esample_pmi=1 if e(sample)==1
codebook land_iso2 if e(sample)==1

*Column 6
reg import_chf_mia_dpct pmi_std i.quarter if esample_pmi==1 , cluster(land_id)
codebook land_iso2 if e(sample)==1


*descriptives
sum export_chf_mia_dpct if esample_covid==1
sum import_chf_mia_dpct if esample_covid==1
sum total_per_1000 if esample_covid==1
sum stringency_index  if esample_covid==1
sum kst_std if esample_covid==1
sum pmi_std if esample_covid==1
